<?php
namespace App\Http\Controllers\H5;

use App\Service\H5\DepartService;
use Illuminate\Http\Request;

class DepartController extends BaseController
{
    //列表
    public function index(Request $request)
    {
        $pas['depart_id'] = $request->post('depart_id', 0);
        $res = DepartService::index($pas);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson(0, '', $res['data']);
    }

    //修改
    public function modify(Request $request)
    {
        $id = $request->post('id', 0);
        $title = $request->post('title', '');
        if ($id) {
            $res = DepartService::modify($id, $title);
        } else {
            $res = DepartService::add($title);
        }
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson();
    }

    //删除
    public function del(Request $request)
    {
        $id = $request->post('id', 0);
        $res = DepartService::del($id);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson();
    }
}